package com.pbking.util.logging.bridges
{
	import com.pbking.util.logging.PBLogEvent;
	import com.pbking.util.logging.PBLogger;
	
	import mx.logging.ILogger;
	import mx.logging.Log;
	
	/**
	 * Creates a bridge to pass the PBLogger logs on to the Flex
	 * Logging Framework.  This does not (yet?) bring loggs from
	 * the Flex Framework into the PBLogger
	 */
	public class PBLogFlexBridge
	{
		private static var initialized:Boolean = false;
		
		public static function initialize():void
		{
			if(!initialized)
			{
				PBLogger.addEventListener(PBLogEvent.LOG, onPbLog);
				
				initialized = true;
			}
		}
		
		private static function onPbLog(event:PBLogEvent):void
		{
			var flexLogger:ILogger = Log.getLogger(event.category); 
			flexLogger.log(event.level, event.message);
		}
	}
}